home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung CD 2 (Tewi)(1994).iso
/
c
/
compiler
/
micro_c
/
fibo.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-02-23
|
546b
|
33 lines
/*
* Program to calculate a fibonacci number.
*
* This demonstrates a heavily RECURSIVE function.
*/
#include \mc\stdio.h
#define MAXFIB 24 /* Largest we can do in 16 bits */
/*
* Recursive function to calculate a fibonacci number
*/
unsigned fibo(num)
unsigned num;
{
if(num <= 2)
return 1;
return fibo(num-1) + fibo(num-2);
}
/*
* Main function to call "fibo" in a loop,
* and display the result.
*/
main()
{
int i;
for(i=1; i <= MAXFIB; ++i)
printf("Fibonacci(%u) = %u\n", i, fibo(i));
}